import axios from "axios";
const instanceECommerce = axios.create({
    baseURL : 'http://127.0.0.1:8888/api/private/v1/',
    timeout:1000
})
function request(req){
    if(req.url != 'login'){
        instanceECommerce.interceptors.request.use(config=>{
            config.headers.Authorization = window.sessionStorage.getItem('token');
            return config;
        })
    }
    instanceECommerce.interceptors.response.use(res=>{
        console.log(res);
        // return res.data;
        if(res.config){
            return res.data;
        }else{
            console.log(res);
            return res;
            
        }        
    })
    return new Promise((resolve,reject)=>{
        instanceECommerce(req).then(data=>{
            resolve(data);
        }).catch(err=>{
            reject(err);
        })
    })
}

export default request;